package com.fl.gulimall.coupon.controller;

import java.util.Arrays;
import java.util.Map;

import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.fl.gulimall.coupon.feign.MemberFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import com.fl.gulimall.coupon.entity.CouponEntity;
import com.fl.gulimall.coupon.service.CouponService;
import com.fl.common.utils.PageUtils;
import com.fl.common.utils.R;



/**
 * 优惠券信息
 *
 * @author chenshun
 * @email 352194871@qq.com
 * @date 2021-07-07 15:06:25
 */
@RestController
@RequestMapping("coupon/coupon")
//@NacosConfigurationProperties(dataId = "gulimall-coupon.yaml" , autoRefreshed = true)
public class CouponController {
    @Autowired
    private CouponService couponService;
    @Autowired
    private MemberFeignService memberFeignService;
//    @Value("${name}")
//    private String name;
//    @Value("${id}")
//    private String id;
    /**
     * 列表
     */
//    @GetMapping("/test")
//    public R test(){
//        return R.ok().put("id",id).put("name",name);
//    }
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = couponService.queryPage(params);

        return R.ok().put("page", page);
    }
    @RequestMapping("/members")
    public R members(){
        CouponEntity entity = new CouponEntity();
        entity.setCouponName("我是优惠券");
        R getmember = memberFeignService.getmember();
        return R.ok().put("entity",entity).put("members",getmember);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CouponEntity coupon = couponService.getById(id);

        return R.ok().put("coupon", coupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CouponEntity coupon){
		couponService.save(coupon);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CouponEntity coupon){
		couponService.updateById(coupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		couponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
